package work20241120;

import java.util.Arrays;
import java.util.Random;

/**
 * @author zdl
 * @date 2024/11/20
 */
public class Demo7 {
    /**
     * 7.数组练习：打乱数组中的数据
     * 需求：定义一个数组，存入1~5.要求打乱数组中所有数据的顺序
     */
    public static void main(String[] args) {
        int[] arr ={1,2,3,4,5};
        Random r = new Random();
        for (int i = 0; i < arr.length ; i++) {
            int index = r.nextInt(arr.length);
            int temp = arr[i];
            arr[i] = arr[index];
            arr[index] = temp;
        }
        System.out.println(Arrays.toString(arr));
    }
}
